package com.victor.modular.system.controller;

import com.victor.common.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;

/**
 * 数据导出下载控制器
 *
 * @author victor
 */
@Controller
@RequestMapping("/export")
public class ExportController extends BaseController {
    private static final String PREFIX = "/system/export/";
    private final static String EXPORT_PACKAGE = "com.victor.common.export.dictmap";

    /**
     * 跳转到  选择导出字段页面
     */
    @RequestMapping("/field")
    public String field(Model model) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        String className = getPara("className");
        Class clazz = Class.forName(EXPORT_PACKAGE + "." + className);
        Method method = clazz.getMethod("getDictory");
        Object obj = clazz.newInstance();
        LinkedHashMap<String, String> fieldList = (LinkedHashMap<String, String>) method.invoke(obj);
        model.addAttribute("fieldList", fieldList);
        return PREFIX + "field.html";
    }

}
